package cn.liulingfengyu.structuralpattern.decoratorpattern;

/**
 * 装饰模式示例
 */
public class DecoratorPatternDemo {
    public static void main(String[] args) {
        // 创建具体组件
        Component component = new ConcreteComponent();

        // 使用装饰器A装饰组件
        Component decoratedComponentA = new ConcreteDecoratorA(component);
        decoratedComponentA.operation();

        System.out.println("-------------");

        // 使用装饰器B装饰组件
        Component decoratedComponentB = new ConcreteDecoratorB(component);
        decoratedComponentB.operation();

        System.out.println("-------------");

        // 使用装饰器A和B同时装饰组件
        Component doubleDecoratedComponent = new ConcreteDecoratorB(new ConcreteDecoratorA(component));
        doubleDecoratedComponent.operation();
    }
}